package 多线程.虚假唤醒;

import java.util.concurrent.locks.LockSupport;

/**
 * @Author kirito
 * @Date 2024/1/4 16:25
 * @PackageName:多线程.虚假唤醒
 * @ClassName: lock
 * @Description:
 * @Version 1.0
 */
public class parkUnpark02 {
    //先执行unpark(),依然可以被唤醒
    public static void main(String[] args) {
        Thread a = new Thread(() -> {
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "\t" + "----come in");
            LockSupport.park();
            System.out.println(Thread.currentThread().getName() + "\t" + "----被唤醒");
        }, "A");
        a.start();
        Thread b = new Thread(() -> {
            LockSupport.unpark(a);
            System.out.println(Thread.currentThread().getName() + "\t" + "----唤醒动作");
        }, "B");
        b.start();

//        B	----唤醒动作
//        A	----come in
//        A	----被唤醒
    }


}
